home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.05 May 90 / virusCheck Code / virusDemo.c < prev   
Encoding:
C/C++ Source or Header  |  1989-12-05  |  2.0 KB  |  68 lines  |  [TEXT/KAHL]

  1. /*    virusDemo.c -- Demonstration of virus self-diagnosis.
  2.             Copyright © 1989 by Michael S. Morton.
  3. */
  4.  
  5. /*    History:
  6.             26-Nov-89 -- MM --    First version.
  7. */
  8.  
  9. #include "virusCheck.h"                                    /* get our own prototypes */
  10.  
  11. /*    Local and C library prototypes: */
  12. void main (void);
  13. int printf (char *formatn, ...);
  14. int getche (void);
  15.  
  16. /*    NOTE: The total length of the CODE resources will vary with your
  17.         development system, so you’ll have to calibrate this.
  18. */
  19. #define CODELENGTH 15948L                                /* actual length of CODE resources */
  20.  
  21. /*    NOTE: The number of CODE resources will vary with how you arrange
  22.         your project.  This count assumes that all source files and libraries
  23.         are grouped into a single segment.  The count is higher because of
  24.         the resources which Think C adds.
  25. */
  26. #define CODECOUNT (1+2)                                    /* actual count of CODE resources */
  27.  
  28. #define WRONGLENGTH (CODELENGTH+1)            /* guaranteed to fail */
  29. #define WRONGCOUNT (CODECOUNT+1)                /* ditto */
  30.  
  31. void main ()
  32. {    char dbgResponse;                                            /* user response for debugger query */
  33.     short debugger;                                                /* debugger installed?  1=y, -1=n */
  34.  
  35.     if (! Count1Resources ('CODE'))
  36.     {    SysBeep (5);
  37.         printf ("This demo must be run standalone, not within Think C\n");
  38.         printf ("Press any key to exit… ");
  39.         getche ();
  40.         ExitToShell ();
  41.     }
  42.  
  43.     printf ("Report unexpected errors with the debugger? ");
  44.     dbgResponse = getche ();
  45.     printf ("\n");
  46.     if ((dbgResponse == 'y') || (dbgResponse == 'Y'))
  47.         debugger = 1;
  48.     else debugger = -1;
  49.  
  50.     printf ("\nChecking -- shouldn’t fail… ");
  51.     if (vCodeCheck (CODECOUNT, CODELENGTH, debugger))
  52.         printf ("FAILED!  *** This application is apparently infected. ***\n");
  53.     else printf ("didn’t fail.\n");
  54.  
  55.     printf ("\nChecking -- should fail on count… ");
  56.     if (vCodeCheck (WRONGCOUNT, CODELENGTH, -1))
  57.         printf ("failed.\n");
  58.     else printf ("DIDN’T FAIL!\n");
  59.  
  60.     printf ("\nChecking -- should fail on length… ");
  61.     if (vCodeCheck (CODECOUNT, WRONGLENGTH, -1))
  62.         printf ("failed.\n");
  63.     else printf ("DIDN’T FAIL!\n");
  64.  
  65.     printf ("\nPress any key to exit… ");
  66.     getche ();
  67. }                                                                                /* end of main () */
  68.